Imports System
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Runtime.InteropServices

Namespace xpComponent.Form
    Public Interface IDisabled
        Property BackColorDisabled() As System.Drawing.Color
        Property ForeColorDisabled() As System.Drawing.Color
    End Interface

    Public NotInheritable Class ControlPaint
        Public Sub New()

        End Sub

        Public Shared ReadOnly Property BorderColor() As Color
            Get
                Return Color.FromArgb(127, 157, 185)
            End Get
        End Property

        Public Shared ReadOnly Property DisabledBorderColor() As Color
            Get
                Return Color.FromArgb(201, 199, 186)
            End Get
        End Property

        Public Shared ReadOnly Property ButtonBorderColor() As Color
            Get
                Return Color.FromArgb(28, 81, 128)
            End Get
        End Property

        Public Shared ReadOnly Property DisabledButtonBorderColor() As Color
            Get
                Return Color.FromArgb(202, 200, 187)
            End Get
        End Property

        Public Shared ReadOnly Property DisabledBackColor() As Color
            Get
                Return Color.FromArgb(236, 233, 216)
            End Get
        End Property

        Public Shared ReadOnly Property DisabledForeColor() As Color
            Get
                Return Color.FromArgb(161, 161, 146)
            End Get
        End Property

        Public Shared Function GetStringFormat(ByVal contentAlignment As ContentAlignment) As StringFormat
            If Not System.Enum.IsDefined(GetType(contentAlignment), contentAlignment) Then
                Throw New System.ComponentModel.InvalidEnumArgumentException("contentAlignment", contentAlignment, GetType(contentAlignment))
            End If

            Dim stringFormat As stringFormat = New stringFormat
            Select Case contentAlignment
                Case contentAlignment.MiddleCenter
                    stringFormat.LineAlignment = StringAlignment.Center
                    stringFormat.Alignment = StringAlignment.Center
                Case contentAlignment.MiddleLeft
                    stringFormat.LineAlignment = StringAlignment.Center
                    stringFormat.Alignment = StringAlignment.Near
                Case contentAlignment.MiddleRight
                    stringFormat.LineAlignment = StringAlignment.Center
                    stringFormat.Alignment = StringAlignment.Far
                Case contentAlignment.TopCenter
                    stringFormat.LineAlignment = StringAlignment.Near
                    stringFormat.Alignment = StringAlignment.Center
                Case contentAlignment.TopLeft
                    stringFormat.LineAlignment = StringAlignment.Near
                    stringFormat.Alignment = StringAlignment.Near
                Case contentAlignment.TopRight
                    stringFormat.LineAlignment = StringAlignment.Near
                    stringFormat.Alignment = StringAlignment.Far
                Case contentAlignment.BottomCenter
                    stringFormat.LineAlignment = StringAlignment.Far
                    stringFormat.Alignment = StringAlignment.Center
                Case contentAlignment.BottomLeft
                    stringFormat.LineAlignment = StringAlignment.Far
                    stringFormat.Alignment = StringAlignment.Near
                Case contentAlignment.BottomRight
                    stringFormat.LineAlignment = StringAlignment.Far
                    stringFormat.Alignment = StringAlignment.Far
            End Select

            Return stringFormat
        End Function

        Public Shared Sub DrawRoundedRectangle(ByVal g As Graphics, ByVal p As Pen, ByVal rc As Rectangle, ByVal size As Size)
            Dim oldSmoothingMode As SmoothingMode = g.SmoothingMode
            g.SmoothingMode = SmoothingMode.AntiAlias
            g.DrawLine(p, CInt(rc.Left + size.Width / 2), rc.Top, CInt(rc.Right - size.Width / 2), rc.Top)
            g.DrawArc(p, rc.Right - size.Width, rc.Top, size.Width, size.Height, 270, 90)
            g.DrawLine(p, rc.Right, CInt(rc.Top + size.Height / 2), rc.Right, CInt(rc.Bottom - size.Height / 2))
            g.DrawArc(p, rc.Right - size.Width, rc.Bottom - size.Height, size.Width, size.Height, 0, 90)
            g.DrawLine(p, CInt(rc.Right - size.Width / 2), rc.Bottom, CInt(rc.Left + size.Width / 2), rc.Bottom)
            g.DrawArc(p, rc.Left, rc.Bottom - size.Height, size.Width, size.Height, 90, 90)
            g.DrawLine(p, rc.Left, CInt(rc.Bottom - size.Height / 2), rc.Left, CInt(rc.Top + size.Height / 2))
            g.DrawArc(p, rc.Left, rc.Top, size.Width, size.Height, 180, 90)
            g.SmoothingMode = oldSmoothingMode
        End Sub

        Public Shared Sub DrawBorder(ByVal g As Graphics, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
            g.DrawRectangle(New Pen(ControlPaint.BorderColor, 0), x, y, width, height)
        End Sub

        Public Shared Sub EraseExcessOldDropDown(ByVal g As Graphics, ByVal newButton As Rectangle)
            g.FillRectangle(New SolidBrush(SystemColors.Window), newButton.X - 2, newButton.Y, 2, newButton.Height + 1)
        End Sub
    End Class
End Namespace